home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C++ / Applications / PICSee Dust 1.01 / Secondary Source / CropPICTs.cpp next >
Encoding:
Text File  |  1995-11-13  |  6.3 KB  |  117 lines  |  [TEXT/CWIE]

  1. /*
  2.     Crop a PICT resource
  3.     ...allowing one to crop a PICS file or a series of PICT files
  4. */
  5.  
  6. #include <QDOffscreen.h>
  7. #include "CropPICTs.h"
  8. #include "PICS_Types.h"
  9. #include "SavePicture.h"
  10. #include "assert_mac.h"
  11. #include "QDUtils.h"        // For CenterRect
  12. #include "FileRegistry.h"
  13.  
  14. // ---------------------------------------------------------------------------
  15.  
  16. /*
  17.     The <picBuffer> is assumed to be at least the same or larger
  18.     dimensions than that of <inputPic>. If you pass the address of
  19.     an empty PicHandle to <croppedPic>, CropPICT will record the
  20.     cropped <inputPic> as a picture to <croppedPic>. If you pass NULL
  21.     instead, no picture will be saved.
  22.     
  23.     <destBuffer> may be the same as <picBuffer>
  24.     <srcCropRect> may be the same as <destCropRect>
  25. */
  26.  
  27. Boolean CropPICT(
  28.     const PicHandle    inputPic,
  29.     const GraphicsBufferPtr    picBuffer,
  30.     const GraphicsBufferPtr    destBuffer,
  31.     const Rect        *srcCropRect,
  32.     const Rect        *destCropRect,
  33.     PicHandle        *croppedPic) {
  34.  
  35.     GWorldPtr    saveWorld;
  36.     GDHandle    saveDev;
  37.     Rect        picRect;
  38.     Boolean        result;
  39.  
  40.     ASSERT(inputPic != NULL);
  41.     ASSERT(picBuffer != NULL);
  42.     ASSERT(destBuffer != NULL);
  43.     ASSERT(srcCropRect != NULL);
  44.     ASSERT(destCropRect != NULL);
  45.  
  46.     GetGWorld(&saveWorld, &saveDev);
  47.     SetGraphicsBuffer(picBuffer);
  48.     picRect = (**inputPic).picFrame;
  49.     FlushRectTopLeft(&picRect);
  50.     DrawPicture(inputPic, &picRect);
  51.  
  52.     result = CapturePICT(picBuffer, destBuffer, srcCropRect, destCropRect, croppedPic);
  53.  
  54.     SetGWorld(saveWorld, saveDev);    
  55.     return(result);
  56. } // END CropPICT
  57.  
  58. // ---------------------------------------------------------------------------
  59.  
  60. Boolean CapturePICT(
  61.     const GraphicsBufferPtr    srcBuffer,
  62.     const GraphicsBufferPtr    destBuffer,
  63.     const Rect        *srcRect,
  64.     const Rect        *destRect,
  65.     PicHandle        *croppedPic) {
  66.  
  67.     GWorldPtr    saveWorld;
  68.     GDHandle    saveDev;
  69.     Rect        clipRect;
  70.     RgnHandle    saveClip;
  71.     
  72.     ASSERT(srcBuffer != NULL);
  73.     ASSERT(destBuffer != NULL);
  74.     ASSERT(srcRect != NULL);
  75.     ASSERT(destRect != NULL);
  76.  
  77.     GetGWorld(&saveWorld, &saveDev);
  78.     SetGraphicsBuffer(destBuffer);
  79.  
  80.     if (croppedPic != NULL) {
  81.         saveClip = NewRgn();
  82.         ASSERT(saveClip != NULL);
  83.         GetClip(saveClip);
  84.         GetGraphicsBufferBounds(destBuffer, (CP_Rect*)&clipRect);
  85.         // It's in global coords so we have to adjust it
  86.         FlushRectTopLeft(&clipRect);
  87.         ClipRect(&clipRect);
  88.     
  89.         *croppedPic = OpenPicture(destRect);
  90.         ASSERT(*croppedPic != NULL);
  91.     }
  92.  
  93.     CopyGraphicsBuffer(srcBuffer, destBuffer,
  94.         (CP_Rect*)srcRect, (CP_Rect*)destRect);
  95.  
  96.     if (croppedPic != NULL) {
  97.         ClosePicture();
  98.         ASSERT(*croppedPic != NULL);
  99.  
  100.         SetClip(saveClip);
  101.         DisposeRgn(saveClip);
  102.         SetGWorld(saveWorld, saveDev);
  103.     }
  104.     
  105.     return(true);
  106. } // END CapturePICT
  107.  
  108. // ---------------------------------------------------------------------------
  109.  
  110. /*
  111.     This routine assumes you already have picked the input <picsFile> and
  112.     created the output <outputFile>. It also assumes that you have set the
  113.     depth of monitor <outputDevice> appropriately, prior to calling the routine.
  114.     (CropPICSFile uses the depth of <outputDevice> to determine the depth
  115.     of the output PICS frames).
  116.     
  117.     Technically, the order of the frames in